import $ from 'jquery'

export const linkedinService = {
    /*
    * 采集的信息
    *  「
    *
    *   教育经历、工作经历
    * 姓名、手机号、邮箱、性别、年龄、学历、城市、公司、职位、学校、专业、行业、标签、工作年限、期望薪资
    *
    * 」
    * */

    // 工作经历展开-展开、个人简介展开-展开、显示全部技能-收起。
    // 采集开始
    collection() {
        console.log('*** linkedin ***');

        let base = getBasicInfo()
        // let desired = getDesired()
        // let eduction = getEducation()
        // let workAndPro = getWorkAndProInfo() // 工作经历和项目经历
        // let evaluation = getEvaluation()
        // let other = getOther()
        // let htmlFile = $util.htmlToString(document) // 获取源html代码

        // 基本信息
        function getBasicInfo() {
            // name: name, // 姓名
            // sex: sex, // 性别
            // imgUrl: imgUrl, // 头像
            // status: status, //在职状态
            // age: age, // 年龄
            // workExperience: workExperience,// 工作年限
            // qualifications: qualifications,// 学历
            // nowCity: nowCity,// 当前所在城市
            // currentSalary: currentSalary,// 当前薪资
            // currentIndustry: currentIndustry,// 当前行业
            // skills: skills // 技能标签
            /*
          * nameZh 中文名
          * nameEn 英文名
          * email 邮件
          * phone 电话
          * qq
          * sex 性别
          * studioTime 工作年限 (秒数)
          * birth 生日 (时间戳)
          * nowCity 当前城市  上海-浦东
          * nowCityType: 'sys',
          * status 当前状态
          * maritalStatus 婚姻状态
          * qualifications 学历,
          * currentYearlySalary 当前年薪
          * currentYearlySalaryRemark 年薪备注
          * */

            var name = $util.getChildText('.authentication-outlet .flex-value-2 > h1').trim()
            var nameZh = name
            var nameEn = ''

            var maritalStatus = ''

            var sex = ''
            var birth = ''
            var studioTime = ''

            var status = ''

            var qualifications = ''

            var nowCity = $('.authentication-outlet .flex-value-2 > p').eq(1).text().trim()
            nowCity = nowCity.replace(/\s/g, '-')

            var currentYearlySalary = ''
            var currentYearlySalaryRemark = ''
            // if (!qq) {
            //     qq = ''
            // }
            // if (!wechat) {
            //     wechat = $('.ci-wechat a').text().trim()
            // }
            // if (!email) {
            //     email = $('.ci-email a').text().trim()
            // }

            return {
                qq: qq,
                wechat: wechat,
                phone: phone,
                email: email,
                nameZh: nameZh,
                nameEn: nameEn,
                maritalStatus: maritalStatus,
                sex: sex,
                studioTime: studioTime,
                birth: birth,
                nowCity: nowCity,
                nowCityType: 'sys',
                status: status,
                qualifications: qualifications,
                currentYearlySalary: currentYearlySalary,
                currentYearlySalaryRemark: currentYearlySalaryRemark,
            }
        }

        // 职业期望
        function getDesired() {

            // desiredCitys: desiredCitys, // 期望城市集合
            // desiredJob: desiredJob, // 期望职位
            // desiredSalary: desiredSalary, // 期望年薪 是个范围 例如 1-2k 12薪
            // industries: industries // 期望行业
            /*
         * desiredCitys 期望城市集合
         * desiredJob 期望职位
         * desiredYearlySalary 期望年薪
         * desiredYearlySalaryRemark 年薪备注
         * industries 期望行业
         * */

            // 行业
            var industries = []
            // 期望职位
            var desiredJob = $('.pv-top-card-section__headline').text().trim()

            // 期望地点
            var desiredCitys = ''

            // 期望年薪
            var desiredYearlySalary = ''
            var desiredYearlySalaryRemark = ''

            return {
                desiredCitys: desiredCitys, // 期望城市集合
                desiredJob: desiredJob, // 期望职位
                desiredYearlySalary: desiredYearlySalary, // 期望年薪
                desiredYearlySalaryRemark: desiredYearlySalaryRemark, // 年薪备注
                industries: industries // 期望行业
            }
        }

        //  工作经历、 项目经历
        function getWorkAndProInfo() {
            // companyName: companyName, // 公司名称
            // area: area || '', // 公司所在地区
            // jobName: jobName, // 职位名称
            // category: category, // 职位类别
            // department: department, // 所在部门
            // leader: leader, // 领导-汇报对象
            // subordinateCount: subordinateCount, //  下属人数
            // workStart: workStart, // 工作时间起
            // workEnd: workEnd, // 工作时间止
            // salary: salary, // 薪资待遇
            // duty: duty, // 职责业绩
            // leavingReason: '' // 离职原因
            //
            /*
        * companyName: 公司名,
        * companyDesc: 描述,
        * jobName: 职位,
        * department: 部门,
        * leader: 汇报对象,
        * areaType: 'sys' 所在地区,
        * areaId: 所在地区,
        * subordinateCount: 下属人数,
        * workStart: 开始时间,
        * workEnd: 结束时间,
        * yearlySalary: 年薪,
        * yearlySalaryRemark: 年薪备注,
        * duty: 职责
        * achievement: 业绩,
        * leavingReason: 离职原因
        * */
            var work = []
            var proInfo = []
            var workEls = $('.authentication-outlet section > div> ul').eq(0).find('li')
            workEls.each(function (index) {
                var detail = $(this)
                var leader = ''
                var subordinateCount = 0
                var department = ''
                var areaId = ''
                var achievement = ''
                var leavingReason = ''
                var jobName = detail.find('.ml5 h3').text().trim()
                var yearlySalary = ''
                var yearlySalaryRemark = ''
                var duty = ''
                var company = detail.find('.ml5 p').eq(0).text().trim()
                var companyDesc = ''
                var workStart = 0
                var workEnd = 0
                var workTime = ''


                workTime = detail.find('.ml5 p > span').eq(0).text().trim()
                workTime = $util.getStartToEndTime(workTime)
                workEnd = workTime.end
                workStart = workTime.start

                var item = {
                    companyName: $util.formatStr(company),
                    companyDesc: $util.formatStr(companyDesc),
                    jobName: jobName,
                    department: department,
                    leader: leader,
                    subordinateCount: subordinateCount,
                    workStart: workStart,
                    workEnd: workEnd,
                    yearlySalary: yearlySalary,
                    yearlySalaryRemark: yearlySalaryRemark,
                    duty: duty,
                    achievement: achievement,
                    leavingReason: leavingReason
                }
                if (areaId) {
                    item.areaId = areaId
                    item.areaType = 'sys'
                }
                work.push(item)
            })
            return {
                work: work,
                pro: proInfo
            }
        }

        // 教育经历
        function getEducation() {
            // schoolName: schoolName, // 学校名称
            //     majorName: majorName, // 专业名称
            //     startDate: startDate, // 开始时间
            //     endDate: endDate, // 结束时间
            //     qualifications: qualifications, // 学位
            //     theEntranceExamination: theEntranceExamination // 是否统招
            /*
         * schoolName: 专业
         * majorName: 开始时间
         * startDate: 开始时间
         * endDate: 结束时间
         * qualifications: 学历
         * theEntranceExamination: 是否统招
         * */
            var education = []
            $('.authentication-outlet section > div> ul').eq(1).find('li').each(function () {
                var detail = $(this)
                var schoolName = detail.find('div> h3').text().trim()
                var majorName = detail.find('div> p').eq(0).text().trim()

                // 学历和专业
                var qualifications = ''
                var theEntranceExamination = undefined
                var time = detail.find('div> p').eq(1).find('span').eq(0).text().trim()
                time = $util.getStartToEndTime(time)
                var startDate = time.start
                var endDate = time.end

                var item = {
                    schoolName: schoolName,
                    majorName: majorName,
                    startDate: startDate,
                    endDate: endDate,
                    qualifications: qualifications,
                    theEntranceExamination: theEntranceExamination
                }
                education.push(item)
            })
            return education
        }

        // 自我评价
        function getEvaluation() {
            var s = ''
            $('._container_iq15dg._inset-compact_sfmhx2 ._bodyText_1e5nen._default_1i6ulk._weightBold_1e5nen').each(function () {
                s = s + $(this).text() + '\n'
            })
            return s
        }

        // 其他 -- 语言能力、证书
        function getOther() {
            // 语言
            var language = ''
            // 证书
            var cert = ''

            return {
                language: language,
                cert: cert
            }
        }

        return {
            href: location.href,
            base: base,
            // desired: desired,
            // work: workAndPro.work,
            // pro: workAndPro.pro,
            // eduction: eduction,
            // other: other,
            // evaluation: evaluation,
            // htmlFile: htmlFile,
            htmlFileName: '领英_' + Date.now() + '.html'
        }
    },
}

